package com.rex;

/**
 * operator enum
 *
 * @author Rex
 * @since 2023/8/3 13:09
 */
public enum OperatorEnums {

    // "like", "notLike", "equals", "notEquals", "lessThan", "lessThanOrEqualTo", "greaterThan", "greaterThanOrEqualTo"

    LIKE("like", "", " like "),
    NOT_LIKE("notLike", "NOT ", " like "),
    EQUALS("equals", "", " = "),
    NOT_EQUALS("notEquals", "", " != "),
    LESS_THAN("lessThan", "", " < "),
    LESS_THAN_OR_EQUAL_TO("lessThanOrEqualTo", "", " <= "),
    GREATER_THAN("greaterThan", "", " > "),
    GREATER_THAN_OR_EQUAL_TO("greaterThanOrEqualTo", "", " >= ");

    private final String key;
    private final String valuePrefix;
    private final String valueSuffix;

    OperatorEnums(String key, String valuePrefix, String valueSuffix) {
        this.key = key;
        this.valuePrefix = valuePrefix;
        this.valueSuffix = valueSuffix;
    }

    /**
     * get the value by the key
     * if there is no value about the param key, then return null
     *
     * @param key key
     * @return {@link OperatorEnums}
     */
    public static OperatorEnums getOperatorEnums(String key) {
        OperatorEnums[] enums = OperatorEnums.values();
        for (OperatorEnums anEnum : enums) {
            if (anEnum.key.equals(key)) {
                return anEnum;
            }
        }
        return null;
    }

    public String getKey() {
        return this.key;
    }

    public String getValuePrefix() {
        return this.valuePrefix;
    }

    public String getValueSuffix() {
        return this.valueSuffix;
    }
}
